package com.sq.goodline.task;

import java.util.UUID;

import org.slf4j.MDC;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Configuration;
import org.springframework.scheduling.annotation.EnableScheduling;
import org.springframework.scheduling.annotation.Scheduled;

import com.sq.goodline.service.MailService;
import com.sq.goodline.service.RemoveFileService;

import lombok.extern.slf4j.Slf4j;

@Slf4j
@Configuration
@EnableScheduling
public class ApiTask {

    @Autowired
    private MailService mailService;
    @Autowired
    RemoveFileService rfervice;
    
    /**
     * temp目录文件定期删除
     */
    @Scheduled(cron = "${job.removeFileTaskCron}")
    private void removeFileTask(){
    	String traceId = UUID.randomUUID().toString().replace("-","");
		MDC.put("TraceId", traceId);//日志追踪
    	String mailSubject="temp目录文件定期删除定时任务";
		StringBuffer mailContext = new StringBuffer();
    	try {
    		log.info("temp目录文件定期删除任务开始...");
    		rfervice.removeTempFile();
    	} catch (Exception e) {
			log.error("temp目录文件定期删除Task异常",e);
			mailContext.append("temp目录文件定期删除定时任务执行异常:\r\n  失败原因："+e.getMessage());
			mailService.sendSimpleMail(mailSubject, mailContext.toString());
		}finally {
			log.info("temp目录文件定期删除任务完毕");
		}
    }
    
     
}
